﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace DetectiveCluedo
{
    public class PlayerCardInfo
    {
        public Player Player;
        public Card Card;
        public bool? PlayerHasCard;

        private List<EPlayerCardInfoStatusReason> _reasonsList;
        private List<int> _suggestionsList;

        private EPlayerCardInfoStatusReason _reason;
        public EPlayerCardInfoStatusReason Reason
        {
            get{return _reason;}

            set
            {
                _reason = value;
                if(!_reasonsList.Contains(value))
                    _reasonsList.Add(value);
            }
        }

        public int Suggestion;
        public string ErrorText;
        public float PossibilityPct;

        public string ToolTip
        {
            get
            {
                string s = "";

                if (PlayerHasCard.HasValue)
                {
                    for (int i = 0; i < _reasonsList.Count; i++)
                    {
                        if (_reasonsList[i] != EPlayerCardInfoStatusReason.Unknown)
                        {
                            if (s != "")
                                s += Environment.NewLine;
                            s += _reasonsList[i].ToString();
                        }
                    }
                    if (Suggestion != -1)
                        s += Environment.NewLine + "Sugg: " + Suggestion.ToString();
                }
                else
                {
                }
                
                return s;
            }
        }

        public PlayerCardInfo()
        {
            _reasonsList = new List<EPlayerCardInfoStatusReason>();
            _suggestionsList = new List<int>();
        }

        public override string ToString()
        {
            string s = "X";
            if(!PlayerHasCard.HasValue)
                s = "?";
            else if(PlayerHasCard.HasValue && PlayerHasCard.Value == false)
                s = "No";
            else if(PlayerHasCard.HasValue && PlayerHasCard.Value == true)
                s = "Yes";

            return string.Format("{0} > {1} [{2}]", Player, Card, s);
        }
    }

    public enum EPlayerCardInfoStatusReason
    {
        MyCard, // implemented
        SomeoneElseHasThatCard, // implemented
        CannotHaveMoreCards, // implemented
        CardShownByOtherPlayer, // implemented
        NooneElseHasThatCard, // implemented
        MustHaveThatCard_ExactNumberOfMissingCardsAndPossibleCards,
        Unknown,
        DoesNotHaveThatCard,  // implemented
        MustHaveThatCard_BySystemOfEliminationUsingOthersSuggestions,
        Solution,
        MustHaveThatCard_DoesNotHaveOtherTwoCardsOfSugg
    }
}
